package com.codingfuture.glacierhardware.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codingfuture.glacierhardware.entity.Company;
import com.codingfuture.glacierhardware.mapper.CompanyMapper;
import com.codingfuture.glacierhardware.service.CompanyService;

import org.apache.poi.hpsf.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



/**
 * @author :zxw
 * @date 2025-03-31 19:05
 * @description:
 */
@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyMapper companyMapper;
    @Override
    public Page<Company> selectByPage(String name, Page<Company> page) {
        QueryWrapper<Company> wrapper = new QueryWrapper<>();
        wrapper.like(!(name==null|| name.isEmpty()),"name", name);
        return companyMapper.selectPage(page,wrapper);
    }

    @Override
    public boolean add(Company company) {
        company.setCreateTime(new Date());
      return companyMapper.insert(company)>0;
    }

    @Override
    public boolean update(Company company) {
        company.setUpdateTime(new Date());
        return companyMapper.updateById(company)>0;
    }

    @Override
    public boolean deleteById(Long id) {
        return companyMapper.deleteById(id)>0;
    }

    @Override
    public Company findById(Long id) {
        return companyMapper.selectById(id);
    }


}
